//
//  XGL_PersonalPublishLiveAlertView.swift
//  XGamesLive
//
//  Created by ios on 2024/5/21.
//

import UIKit

class XGL_PersonalPublishLiveAlertView: UIView {

    typealias SureBlock = ()->Void
    
    private var handler: SureBlock?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func showAlertView(handler: SureBlock?){
        self.handler = handler
        let contentView = UIView()
        let imageView = UIImageView(image: imageWithName("icon_xgl_alert_background"))
        let titleText = UILabel().then { make in
            make.text = "Warn"
            make.font = UIFont.pingfangSC_Regular(fontSize: 22.0)
            make.textColor = .white
        }
        let contentText = UILabel().then { make in
            make.textColor = UIColor.hexColor("#A2A2A2")
            make.font = UIFont.pingfangSC_Regular(fontSize: 16.0)
            make.numberOfLines = 0
            make.lineBreakMode = .byWordWrapping
            make.textAlignment = .center
            make.text = "It is strictly forbidden for minors to recharge and consume, and it is strictly forbidden to promote political, pornographic, sensitive topics and other related content, otherwise the platform will be banned for 24 hours!"
        }
        let dismissButton = UIButton().then { make in
            make.setImage(imageWithName("icon_xgl_alert_close_gray"), for: .normal)
            make.addTarget(self, action: #selector(self.closeAction), for: .touchUpInside)
        }
        let sureButton = UIButton().then { make in
            make.setTitle("Confirm", for: .normal)
            make.setTitleColor(UIColor.hexColor("#191A1D"), for: .normal)
            make.titleLabel?.font = UIFont.pingfangSC_Regular(fontSize: 16.0)
            make.backgroundColor = UIColor.hexColor("#80FFE6")
            make.layerCornerRadius = 20.0
            make.addTarget(self, action: #selector(self.sureAction), for: .touchUpInside)
        }
        contentView.addSubviews([imageView,titleText,contentText,dismissButton,sureButton])
        self.addSubview(contentView)
        imageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        titleText.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(30.0)
        }
        dismissButton.snp.makeConstraints { make in
            make.right.equalTo(-12)
            make.top.equalTo(12.0)
            make.width.height.equalTo(24.0)
        }
        contentText.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.left.equalTo(15.0)
            make.top.equalTo(titleText.snp.bottom).offset(14.0)
        }
        sureButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(contentText.snp.bottom).offset(16.0)
            make.height.equalTo(40.0)
            make.width.equalTo(conversionWithScrennWidth(value: 215.0))
        }
        contentView.snp.makeConstraints { make in
            make.width.equalTo(conversionWithScrennWidth(value: 315.0))
            make.bottom.equalTo(sureButton.snp.bottom).offset(22.0)
            make.center.equalToSuperview()
        }
    }
}

extension XGL_PersonalPublishLiveAlertView{
    @objc private func sureAction(){
        if let block = self.handler {
            block()
        }
        self.removeFromSuperview()
    }
    @objc private func closeAction(){
        self.removeFromSuperview()
    }
}
